<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>消息订阅与发布</title>
    <script src="../../src/pub-sub/index.js"></script>
</head>
<body>
    <script>
        //订阅一个频道
        let pid = PubSub.subscribe('pay', data => {
            console.log('商家接到了订单, 准备开始制作', data);
        });

        let pid2 = PubSub.subscribe('pay', data => {
            console.log('骑手接到了订单, 准备开始去取餐', data);
        });

        PubSub.subscribe('cancel', data => {
            console.log('商家接到了取消的请求');
        });

        //输出唯一的id
        // console.log(pid, pid2);
        //发布消息
        // PubSub.publish('pay', {
        //     title: '鱼香肉丝盖饭',
        //     price: 20,
        //     pos: '三年二班'
        // });

        //取消订阅
        // PubSub.unsubscribe('pay');
        PubSub.unsubscribe('token_2');


        PubSub.publish('pay', {
            title: '鱼香肉丝盖饭',
            price: 20,
            pos: '三年二班'
        });

    </script>
</body>
</html>